package demo1.Panels;

import javax.swing.*;
import java.awt.*;

public class MySinLine extends JPanel {
    private Color penColor = new Color(0,0,0);
    private int A = 75;
    private int T = 150;
    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        int width = this.getWidth();
        int height = this.getHeight();
        g.setColor(new Color(255, 255, 255, 255));
        g.fillRect(0,0,width,height);

        g.setColor(penColor);
        int x0 = 0;
        int y0 = 75;
        for (int x = 0; x < width; x += 3) {
            double y = A * Math.sin((2 * Math.PI * x) / T) + 75;
            g.drawLine(x0,y0,x,(int)y);
            x0 = x;
            y0 = (int)y;
        }
        g.drawLine(0,75,300,75);
    }

    public Color getPenColor() {
        return penColor;
    }

    public void setPenColor(Color penColor) {
        this.penColor = penColor;
    }

    public int getA() {
        return A;
    }

    public void setA(int a) {
        A = a;
    }

    public int getT() {
        return T;
    }

    public void setT(int t) {
        T = t;
    }
}
